<?php
namespace Wulian\Model;

use Common\Model\CommonModel;

class WlFlowRecordModel extends CommonModel {


    /**
     * 插入流量值记录
     */
    public function addFlowRecord($card_number,$card = ""){
        $year = date("Y");
        $month = date("m");
        $m_card = M("WlCard");
        $where = array("card_number"=>$card_number,"flow_record_year"=>$year,"flow_record_month"=>$month);
        $flow_record = $this->where($where)->find();
        if(empty($card)){
            $card = $m_card->where(array("card_number"=>$card_number))->find();
        }
        if(!$flow_record){
            $insert = array(
                "card_number"=>$card_number,
                'card_iccid'=>$card["card_iccid"],
                "flow_record_year"=>$year,
                "flow_record_month"=>$month,
                "package_data_month"=>$card["package_data_month"],
                "package_data_add"=>$card["package_data_add"],
            );
            $result = $this->add($insert);
        }else{
            $result = $this->where($where)->save(array("package_data_month"=>$card["package_data_month"],'package_data_add'=>$card["package_data_add"]));
        }
        return $result;
    }
}